<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<%--/*
* 创建作者:   秦令泽
* 创建日期:   19:18 2019/8/15
* 方法介绍:   设备类型编辑能力项穿梭框
* 参数说明:
* @return
*/--%>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>设备类型--编辑能力项</title>
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <link rel="stylesheet" href="/lims/css/eleTree.css">
    <script src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script type="text/javascript" src="../../js/jquery/jquery-1.9.1.js"></script>
    <script src="../../js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lims/js/limstree.js?v=2019080601" type="text/javascript" charset="utf-8"></script>
    <style>
        .layui-card-header {
            border-bottom: 1px solid #eee;
            /*background: #fff;*/
            /*margin-top: 5px;*/
        }

        .main-row {
            display: flex;
            width: 100%;
            box-sizing: border-box;
            /*padding: 0 10px;*/
            font-size: 15px;
            line-height: 16px;
            /*margin-top: 15px;*/
        }

        .side-col {
            width: 100%;
            /* padding-right: 12px;*/
        }

        .panel {
            position: relative;
            /*margin-bottom: 20px;*/
            background-color: #fff;
            border: 1px solid transparent;
            border-radius: 4px;
            -webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .05), 0 2px 6px 0 rgba(0, 0, 0, .045);
            box-shadow: 0 1px 1px rgba(0, 0, 0, .05), 0 2px 6px 0 rgba(0, 0, 0, .045);

        }

        .panel-heading {
            padding: 12px 48px 12px 20px;
            border-bottom: 1px solid transparent;
            border-top-left-radius: 3px;
            border-top-right-radius: 3px;
        }

        .panel-title {
            font-size: 14px;
            font-weight: 700;
            line-height: 20px;
            cursor: pointer;
        }

        .panel-body {
            padding: 20px;
            padding-top: 0;
        }

        .main-col {
            width: 70%;
        }

        .row-module + .row-module {
            margin-top: 5px;
        }

        .row-module {
            max-width: 550px;
            min-width: 400px;
        }

        .table-row {
            display: table;
            width: 100%;
            table-layout: fixed;
        }

        .col-module {
            min-width: 200px;
        }

        .col-shorts {
            width: 110px;
        }

        .table-form > tbody > tr > td, .table-form > tbody > tr > th, .table-form > tfoot > tr > td, .table-form > thead > tr > th {
            padding: 7px;
            vertical-align: middle;
            border-bottom: none;
        }

        .table td, .table th {
            padding: 8px 10px;
            line-height: 1.42857143;
            vertical-align: top;
            border-bottom: 1px solid #cbd0db;
            -webkit-transition: background .2s cubic-bezier(.175, .885, .32, 1);
            -o-transition: background .2s cubic-bezier(.175, .885, .32, 1);
            transition: background .2s cubic-bezier(.175, .885, .32, 1);
        }

        .text-middle {
            font-size: 14px;
        }

        .text-middle img {
            width: 21px;
            margin-bottom: 4px;
        }

        .col-actions {
            width: 88px;
            padding-left: 5px;
        }

        .iptbox {
            display: flex;
            margin: 10px 0;
        }

        .longs {
            width: 450px;
        }

        .shorts {
            width: 150px;
        }

        .pnul {
            width: 60px;
        }

        .btnls {
            display: flex;
            align-items: center;
            margin-left: 5px;
        }

        .rtfix {
            overflow-y: auto;
            height: 288px;
        }

        /*滚动条样式*/
        .rtfix::-webkit-scrollbar { /*滚动条整体样式*/
            width: 4px; /*高宽分别对应横竖滚动条的尺寸*/
            height: 4px;
        }

        .rtfix::-webkit-scrollbar-thumb { /*滚动条里面小方块*/
            border-radius: 5px;
            -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
            background: rgba(0, 0, 0, 0.2);
        }

        .rtfix::-webkit-scrollbar-track { /*滚动条里面轨道*/
            -webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
            border-radius: 0;
            background: rgba(0, 0, 0, 0.1);
        }

        .layui-layer-btn .layui-layer-btn0 {
            background-color: #009688 !important;
            border-color: #009688 !important;
        }

        .layui-layer-btn .layui-layer-btn1 {
            background-color: #FF5722 !important;
            border-color: #FF5722 !important;
            color: #fff;
        }

        #hide {
            display: none;
        }

        .layui-colla-item {
            position: relative;
        }
    </style>

</head>
<body>
<div class="layui-btn-container">
    <button type="button" style="display: none;" id="btn1" class="layui-btn" lay-demotransferactive="getData">获取右侧数据
    </button>
</div>


<div class="demo-transfer" style="margin:0 auto;width:100%;">
    <div class="layui-transfer layui-form layui-border-box" lay-filter="LAY-transfer-1"
         style="margin:0 auto;width:83%;">
        <div class="layui-transfer-box" data-index="1" style="width: 300px; height: 380px;">
            <div class="layui-transfer-header" id="selected" >
                <input type="checkbox" name="layTransferRightCheckAll"
                       lay-filter="layTransferCheckbox" lay-type="all" lay-skin="primary"
                       title="未选能力项">
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" >
                    <span>未选能力项</span><i
                        class="layui-icon layui-icon-ok" ></i></div>
            </div>
            <div class="layui-transfer-search" id="inputleft"><i class="layui-icon layui-icon-search"></i>
                <input type="input" class="layui-input" placeholder="关键词搜索">
            </div>
            <%--树结构--%>
            <div class="main-row">
                <div class="side-col">
                    <div class="panel  rtfix">
                        <div class="panel-body">
                            <div class="eleTree ele1" id="data1" lay-filter="data1" style="float:left"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-transfer-active" id="mobile">
            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-btn-disabled" data-index="0"><i
                    class="layui-icon layui-icon-next"></i></button>
            <button type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-btn-disabled" data-index="1"><i
                    class="layui-icon layui-icon-prev"></i></button>
        </div>
        <div class="layui-transfer-box" data-index="1" style="width: 300px; height: 380px;">
            <div class="layui-transfer-header" id="notselected">
                <input type="checkbox" name="layTransferRightCheckAll"
                       lay-filter="layTransferCheckbox" lay-type="all" lay-skin="primary"
                       title="已选能力项">
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" >
                    <span>已选能力项</span>
                    <i class="layui-icon layui-icon-ok"></i></div>
            </div>
            <div class="layui-transfer-search" id="inputright"><i class="layui-icon layui-icon-search"></i>
                <input type="input" class="layui-input" placeholder="关键词搜索">
            </div>

            <%--树结构--%>
            <div class="main-row">
                <div class="side-col">
                    <div class="panel  rtfix">
                        <div class="panel-body">
                            <div class="eleTree ele1" id="ele1data2" lay-filter="ele1data2" style="float:left"></div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>

<script>
    var btnNum = 0; //为右侧树第一次
    // 获取地址栏参数值
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
    var idkey = getQueryString("id");
    var el, //左侧树
        el2, //右侧树
        data,
        dataleft=[], //左侧树的数据
        dataright=[]; // 右侧树的数据


    layui.use(['transfer', 'util', 'form', 'layer', 'form', 'eleTree', 'element', 'code', 'laytpl', 'soulTable', 'tree'], function () {
        var $ = layui.$
            , transfer = layui.transfer
            , util = layui.util
            , form = layui.form
            , eleTree = layui.eleTree,
            $ = layui.jquery,
            laytpl = layui.laytpl,
            soulTable = layui.soulTable;



        //初始数据
        $.post('/equipCapy/findBytyoeCodeTree?equipTypeId=' + idkey, function (res) {
            data = res.data
            for (var i = 0; data.length > i; i++) {
                var obj={
                    id:data[i].id,
                    isLeaf:data[i].isLeaf,
                    label:data[i].label,
                    status:data[i].status
                }
                var obj2={
                    id:data[i].id,
                    isLeaf:data[i].isLeaf,
                    label:data[i].label,
                    status:data[i].status
                }
                //为2一定有子级
                if (data[i].status === '2') {
                    if (!data[i].isLeaf) {
                        obj.children=data[i].children
                        var children = []; //左侧
                        var children2 = []; //右侧
                        for (var j = 0; data[i].children.length > j; j++) {
                            if (data[i].children[j].status == '0') { //zuo
                                children.push(data[i].children[j]);
                            } else if (data[i].children[j].status == '1') { //you
                                children2.push(data[i].children[j]);
                            }
                        }
                        if (children.length > 0) {//左
                            obj.children = children;
                            dataleft.push(obj);
                        }

                        if (children2.length > 0) { //右
                            obj2.children = children2;
                            dataright.push(obj2);
                        }
                    }
                } else {
                    //不判断有无子级
                    if (data[i].status === '0') { //zuo
                        dataleft.push(data[i]);
                    } else if (data[i].status === '1') { //you
                        dataright.push(data[i]);
                    }
                }


                /* if (!data[i].isLeaf) {
                     /!* var children = []; //左侧
                     var children2 = []; //右侧
                     for (var j = 0; data[i].children.length > j; j++) {
                         if (data[i].children[j].status == '0') {
                             children.push(data[i].children[j]);
                         } else if (data[i].children[j].status == '1') {
                             children2.push(data[i].children[j]);
                         }
                     }
                     if (children.length > 0) {
                         data[i].children = children; //左
                         dataleft.push(data[i]);
                     } else if (children2.length > 0) {
                         data[i].children = children2; //右
                         dataright.push(data[i]);
                     }*!/
                 } else {
                     //dataleft.push(data[i]);
                     //为2肯定有子级
                 }*/
            }
            //左侧树结构
            ele1(dataleft);
            //右侧树结构
            ele2(dataright);
        })

        //左侧树结构
        function ele1(dataleft) {
            //左侧
            el = eleTree.render({
                elem: '#data1',
                data: dataleft,
                showCheckbox: true,
                showLine: true,
                checkOnClickNode: false,
            });
        }

        //右侧树结构
        function ele2(dataright) {
            //右侧
            el2 = eleTree.render({
                elem: '#ele1data2',
                data: dataright,
                showCheckbox: true,
                showLine: true,
                checkOnClickNode: false,
            });
        }

        // input被选中事件，左侧监听事件
        eleTree.on("nodeChecked(data1)", function (d) {
            var isChecked = d.isChecked;
            var data = d.data;
            if (isChecked) {
                $("#mobile").find("button[data-index='0']").removeClass("layui-btn-disabled");
            } else {
                var i = true;
                $("#data1").find('div[class="eleTree-node "]').each(function (index) {
                    var status = $(this).children('div[class="eleTree-node-content"]').find('input[name="eleTree-node"]').attr("eletree-status");
                    if (status == '1') {
                        i = false
                    }
                });
                if (i) {
                    $("#mobile").find("button[data-index='0']").addClass("layui-btn-disabled");
                }
            }
        })

        // input被选中事件，右侧监听事件
        eleTree.on("nodeChecked(ele1data2)", function (d) {
            var isChecked = d.isChecked;
            if (isChecked) {
                $("#mobile").find("button[data-index='1']").removeClass("layui-btn-disabled");
            } else {
                var i = true;
                $("#ele1data2").find('div[class="eleTree-node "]').each(function (index) {
                    var status = $(this).children('div[class="eleTree-node-content"]').find('input[name="eleTree-node"]').attr("eletree-status");
                    if (status == '1') {
                        i = false
                    }
                });
                if (i) {
                    $("#mobile").find("button[data-index='1']").addClass("layui-btn-disabled");
                }
            }

        })


        //监听搜索事件
        $('#inputleft').find('input').bind('input propertychange', function() {
            console.log("正在输入...");

            var item=$('#inputleft').find('input').val();
            var fdata=searchreset(dataleft,item);
            ele1(fdata);
            //状态全部为空
            el.unCheckNodes();
            el.unExpandAll();
            $("#mobile").find("button[data-index='0']").addClass("layui-btn-disabled");
            $('#selected').find('div').removeClass('layui-form-checked');
        });
        $('#inputright').find('input').bind('input propertychange', function() {
            console.log("正在输入...2");

            var item=$('#inputright').find('input').val();
            var fdata=searchreset(dataright,item);
            ele2(fdata);
            el2.unCheckNodes();
            el2.unExpandAll();
            $("#mobile").find("button[data-index='1']").addClass("layui-btn-disabled");
            $('#notselected').find('div').removeClass('layui-form-checked');
        });

        //左侧全选
        $('#selected').click(function () {
            var is=$('#selected').find('input').is(':checked');
            if (is){
                var leftId=[];
                for(var i=0;dataleft.length>i;i++){
                    var id;
                    if (!dataleft[i].isLeaf){
                        for (var j=0;dataleft[i].children.length>j;j++){
                            id=dataleft[i].children[j].id
                            leftId.push(id);
                        }
                    }
                    id=dataleft[i].id
                    leftId.push(id);
                }
                //el.expandAll()
                console.log(leftId)
                el.setChecked(leftId,false); //选中节点
                $("#mobile").find("button[data-index='0']").removeClass("layui-btn-disabled");
            }else{
                el.unCheckNodes();
                //el.unExpandAll();
                $("#mobile").find("button[data-index='0']").addClass("layui-btn-disabled");
            }
        });

        //右侧全选
        $('#notselected').click(function (){
            var is=$('#notselected').find('input').is(':checked');
            if (is){
                var rightId=[];
                for(var i=0;dataright.length>i;i++){
                    var id;
                    if (!dataright[i].isLeaf){
                        for (var j=0;dataright[i].children.length>j;j++){
                            id=dataright[i].children[j].id
                            rightId.push(id);
                        }
                    }
                    id=dataright[i].id
                    rightId.push(id);
                }
                //el2.expandAll()
                el2.setChecked(rightId,false);
                $("#mobile").find("button[data-index='1']").removeClass("layui-btn-disabled");
            }else{
                el2.unCheckNodes()
                //el2.unExpandAll()
                $("#mobile").find("button[data-index='1']").addClass("layui-btn-disabled");
            }
        });


        //左右移动只是操作数据重置树结构没有用到节点的增删改，完全逻辑操作数据
        //移动到右侧
        $("button[data-index='0']").click(function () {
            var Moveright = $("button[data-index='0']").attr("class").indexOf("layui-btn-disabled"); //移动到右侧
            if (Moveright === -1) {

                var isel=isSelectAll(0,dataleft);
                console.log(isel);
                var el1data = datachildren(isel, dataleft); //已选中
                var net=notdata1(isel,dataleft); //未选中
                if (dataright.length>0){
                    dataright=Combine(el1data, dataright);
                }else {
                    dataright=el1data;
                }
                dataleft=net;
                //重新渲染
                ele1(dataleft);
                ele2(dataright);

                el.unCheckNodes()
                el2.unCheckNodes();
                //复选框
                $('#selected').find('div').removeClass('layui-form-checked');
                $('#selected').find('input').prop('disabled',false);
                $('#inputleft').find('input').val('');
                $('#inputright').find('input').val('');
                //移除按钮样式
                $("#mobile").find("button[data-index='1']").addClass("layui-btn-disabled");
                $("#mobile").find("button[data-index='0']").addClass("layui-btn-disabled");
            }
        });

        //移动到左侧
        $("button[data-index='1']").click(function () {
            var Moveleft = $("button[data-index='1']").attr("class").indexOf("layui-btn-disabled"); //移动到左侧
            if (Moveleft === -1) {
                var isel = isSelectAll(1,dataright);
                var rightNot=notdata1(isel,dataright); //右侧树结构未选中的数据
                var selected=datachildren(isel,dataright); //重置右侧树已选中的数据
                if (dataleft.length>0){
                    dataleft=Combine(selected, dataleft);
                }else {
                    dataleft=selected;
                }
                dataright=rightNot;
                ele1(dataleft); //左侧树
                ele2(dataright); //右侧树
                el.unCheckNodes();
                el2.unCheckNodes();
                $('#notselected').find('div').removeClass('layui-form-checked');
                $('#notselected').find('input').prop('disabled',false);
                $('#inputleft').find('input').val('');
                $('#inputright').find('input').val('');
                $("#mobile").find("button[data-index='1']").addClass("layui-btn-disabled");
                $("#mobile").find("button[data-index='0']").addClass("layui-btn-disabled");
            }
        });

        //返回数组，判读是否是全选状态
        function isSelectAll(status,data) {
            var iseletree=[];
            var isel;
            if (status===0){ //获取左侧
                isel = el.getChecked(false, true); //获取选中的节点
            }else if(status===1){ //获取右侧
                isel = el2.getChecked(false, true); //获取选中的节点
            }
            var li=getArrEqual(data,isel);
            for (let i=0;li.length>i;i++){
                var eleStatus;
                if (status===0){
                    eleStatus=$('#data1 div[data-id="'+li[i].id+'"] .eleTree-node-content :eq(0) input[name="eleTree-node"]').attr('eletree-status');
                }else if(status===1){
                    eleStatus=$('#ele1data2 div[data-id="'+li[i].id+'"] .eleTree-node-content :eq(0) input[name="eleTree-node"]').attr('eletree-status');
                }
                //全选状态
                if (eleStatus==='1'){
                    var obj={
                        id:li[i].id,
                        label:li[i].label
                    }
                    if (!li[i].isLeaf){
                        for (let j=0;li[i].children.length>j;j++){
                            var obj2={
                                id:li[i].children[j].id,
                                label:li[i].children[j].label
                            }
                            iseletree.push(obj2);
                        }
                    }
                    iseletree.push(obj);
                }else if(eleStatus==='2') { //半选状态
                    for(let k=0;isel.length>k;k++){
                        var is=a(isel[k].id,iseletree);
                        if (is){
                            continue
                        }else{
                            var obj3={
                                id:isel[k].id,
                                label:isel[k].label
                            }
                            iseletree.push(obj3);
                        }
                    }
                }
            }
            return iseletree;
        }


        //判断数组是否包含,返回true和false
        function a(item,array) {
            for (var i=0;array.length>i;i++){
                if (array[i].id===item){
                    return true;
                }
            }
            return false;
        }

        //判断是否包含，返回下标
        function b(item,array) {
            for (var i=0;array.length>i;i++){
                if (array[i].id===item){
                    return i;
                }
            }
            return -1;
        }

        //重置选中数据
        function datachildren(data, arr) {
            var pdata1=[];
            var cdata=[];
            //选中的父级
            for (var i = 0; arr.length > i; i++) {
                for (var j = 0; data.length > j; j++) {
                    if (arr[i].id === data[j].id) {
                        var obj={
                            id:arr[i].id,
                            isLeaf:arr[i].isLeaf,
                            label:arr[i].label
                        }
                        if (!arr[i].isLeaf){
                            obj.children=arr[i].children;
                        }
                        cdata.push(obj);
                    }
                }
            }

            //选中的子级
            for (var k = 0; cdata.length > k; k++) {
                if (!cdata[k].isLeaf) {
                    var children = [];
                    for (var q = 0; cdata[k].children.length > q; q++) {
                        var obj=a(cdata[k].children[q].id,data);
                        if (obj){
                            children.push(cdata[k].children[q]);
                            continue;
                        }
                    }
                    cdata[k].children=children;
                }
                pdata1.push(cdata[k]);
            }
            return pdata1;
        }

        //重置未选中的数据
        function notdata1(data, dataAll) {
            var netdata = [];
            for (var i=0;dataAll.length>i;i++){
                var is=a(dataAll[i].id,data);
                if (is){
                    if (!dataAll[i].isLeaf){
                        var children=[];
                        //包含并且有子级
                        for (var j=0;dataAll[i].children.length>j;j++){
                            //判断子级是否包含
                            var is=a(dataAll[i].children[j].id,data);
                            if(!is){ //不包含
                                children.push(dataAll[i].children[j]);
                            }
                        }
                        //判断子级长度是否一致
                        if (children.length>0){
                            var obj={
                                id:dataAll[i].id,
                                isLeaf:dataAll[i].isLeaf,
                                label:dataAll[i].label
                            }
                            if (!dataAll[i].isLeaf){
                                obj.children=children;
                            }
                            /*dataAll[i].children=children;*/
                            netdata.push(obj);
                        }
                    }
                    continue;
                }else {
                    netdata.push(dataAll[i]);
                }
            }
            return netdata;
        }

        //重置已选中的数据和未选中的数据,
        function Combine(edData,notData) {
            var combineData=[];
            var data1=[]
                ,data2=[];
            for (var i =0;edData.length>i;i++){
                var obj={
                    id:edData[i].id,
                    isLeaf:edData[i].isLeaf,
                    label:edData[i].label
                }
                if (!edData[i].isLeaf){
                    obj.children=edData[i].children;
                }
                if (edData.length>=notData.length){
                    data1.push(obj);
                }else {
                    data2.push(obj);
                }
            }

            for (var i =0;notData.length>i;i++){
                var obj={
                    id:notData[i].id,
                    isLeaf:notData[i].isLeaf,
                    label:notData[i].label
                }
                if (!notData[i].isLeaf){
                    obj.children=notData[i].children;
                }
                if (edData.length>=notData.length){
                    data2.push(obj);
                }else {
                    data1.push(obj);
                }
            }

            var is=getArrEqual(data1,data2);
            if (is.length>0){
                for (var i=0;data1.length>i;i++){
                    var is=b(data1[i].id,data2);
                    if (is>=0){
                        if (!data1[i].isLeaf){
                            var comChildren=[]; //存放合并子级
                            for (var j=0;data1[i].children.length>j;j++){
                                comChildren.push(data1[i].children[j]);
                            }
                            for (var k=0;data2[is].children.length>k;k++){
                                comChildren.push(data2[is].children[k]);
                            }
                            data1[i].children=comChildren;
                            combineData.push(data1[i]);
                        }else {
                            combineData.push(data1[i]);
                        }
                    }else { //不包含并且无子级

                        /*var not=getArrNotEqual(data1,data2);
                        console.log(not);
                        for(var cd=0;not.length>cd;cd++){
                            combineData.push(not[cd]);
                        }*/
                        var arr=[];
                        for(var cd=0;data2.length>cd;cd++){
                            if(data2[cd].isLeaf){
                                arr.push(data2[cd]);
                            }
                        }
                        var end=deteleObject(arr);
                        for (var en=0;end.length>en;en++){
                            combineData.push(end[en]);
                        }
                        combineData.push(data1[i]);
                    }
                }
            }else{
                for (var j=0;data1.length>j;j++){
                    combineData.push(data1[j]);
                }
                for (var k=0;data2.length>k;k++){
                    combineData.push(data2[k]);
                }
            }

            var delobj=deteleObject(combineData);
            return delobj;
        }

        //返回数组两个相同的
        function getArrEqual(arr1, arr2) {
            let newArr = [];
            for (let i = 0; i < arr2.length; i++) {
                for (let j = 0; j < arr1.length; j++) {
                    if(arr1[j].id === arr2[i].id){
                        newArr.push(arr1[j]);
                        /*newArr.push(arr2[i]);*/
                    }
                }
            }
            return newArr;
        }

        function getArrNotEqual(arr1, arr2) {
            let newArr = [];
            for (let i = 0; i < arr2.length; i++) {
                for (let j = 0; j < arr1.length; j++) {
                    if(arr1[j].id != arr2[i].id){
                        newArr.push(arr1[j]);
                        newArr.push(arr2[i]);
                    }
                }
            }
            return newArr;
        }

        function deteleObject(obj) {
            var uniques = [];
            var stringify = {};
            for (var i = 0; i < obj.length; i++) {
                var keys = Object.keys(obj[i]);
                keys.sort(function(a, b) {
                    return (Number(a) - Number(b));
                });
                var str = '';
                for (var j = 0; j < keys.length; j++) {
                    str += JSON.stringify(keys[j]);
                    str += JSON.stringify(obj[i][keys[j]]);
                }
                if (!stringify.hasOwnProperty(str)) {
                    uniques.push(obj[i]);
                    stringify[str] = true;
                }
            }
            uniques = uniques;
            return uniques;
        }

        //搜索的重置数据
        function searchreset(isData,item) {
            var search=[];
            var data=[];
            if (item!=undefined && item!=''){
                for (var s =0;isData.length>s;s++){
                    var obj={
                        id:isData[s].id,
                        isLeaf:isData[s].isLeaf,
                        label:isData[s].label
                    }
                    if (!isData[s].isLeaf){
                        obj.children=isData[s].children;
                    }
                    data.push(obj);
                }
                for (var i=0;data.length>i;i++){
                    var is=false;
                    //判断父级包不包含
                    if(data[i].label.indexOf(item)>=0){
                        search.push(data[i]);
                    }else{
                        if (!data[i].isLeaf){
                            var chsearch=[];
                            for (var j=0;data[i].children.length>j;j++){
                                if(data[i].children[j].label.indexOf(item)>=0){
                                    chsearch.push(data[i].children[j]);
                                    is=true;
                                }
                            }
                        }
                        if (is){
                            data[i].children=chsearch;
                            search.push(data[i]);
                        }
                    }

                }
            }else{
                return isData;
            }
            return search;
        }
    });

    // 父调用子页面的方法
    function getStr() {
        return dataright
    }


</script>
</body>


</html>
